﻿using System;
using Quartz;



namespace MvcForum.Net.Bussiness.Jobs
{
    public class SendEmail : IJob
    {
        
        protected static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(SendEmail));

        public void Execute(IJobExecutionContext context)
        {
            var _email = EmailQueueRepo.List();

            foreach (var e in _email)
            {

                log.Info(string.Format("Begin send email: {0}",e.Id));

                try
                {
                    ForumContext.SendMail(e.From, e.To, e.Subject, e.Body);

                    EmailQueueRepo.Del(e.Id);

                }
                catch (Exception ex)
                {
                    log.Info(ex.ToString());
                    
                }

              
            }

        }

     /*   public void Execute(JobExecutionContext context)
        {
            var _email = EmailQueueRepo.List();
            foreach (var e in _email)
            {


             //   ForumContext.SendMail(e.From, e.To, e.Subject, e.Body);

                EmailQueueRepo.Del(e.Id);
            }
        }*/
    }
}
